/*
  @author NormanMises
  @date 2023/6/3 - 21:19
*/

package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.user;
import com.example.demo.service.impl.utils.UserDetaileImpl;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.*;
@Service
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        QueryWrapper<user> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",username);
        user user=userMapper.selectOne(queryWrapper);
        if(user==null){
            throw new RuntimeException("没用该用户");
        }
        return new UserDetaileImpl(user);
    }
}
